<?php
/**
 *+------------------
 * Lflow
 *+------------------
 * Copyright (c) 2023~2030 gitee.com/liu_guan_qing All rights reserved.本版权不可删除，侵权必究
 *+------------------
 * Author: Mr.April(405784684@qq.com)
 *+------------------
 */
declare (strict_types=1);

namespace lflow\entity;

use lflow\access\orm\model\VirtualModel;
use lflow\model\TaskModel;

class Task
{
    use Common;

    public static string $KEY_ACTOR = "S-ACTOR";
    /**
     * 主键ID
     */
    private string $id;

    /**
     * 版本
     */
    private int $version = 0;
    /**
     * 流程实例ID
     */
    private string $order_id;
    /**
     * 任务名称
     */
    private string $task_name;
    /**
     * 任务显示名称
     */
    private string $display_name;
    /**
     * 参与方式（0：普通任务；1：参与者会签任务）
     */
    private int $perform_type;
    /**
     * 任务类型（0：主办任务；1：协办任务）
     */
    private int $task_type;
    /**
     * 任务处理者ID
     */
    private string $operator;
    /**
     * 任务创建时间
     */
    private string $create_time;
    /**
     * 任务完成时间
     */
    private string $finish_time;
    /**
     * 期望任务完成时间
     */
    private string $expire_time;
    /**
     * 期望的完成时间date类型
     */

    private string $expire_date;
    /**
     * 提醒时间date类型
     */
    private string $remind_date;
    /**
     * 任务关联的表单url
     */
    private string $action_url;
    /**
     * 任务参与者列表
     */
    private array $actorIds = [];
    /**
     * 父任务Id
     */
    private string $parent_task_id;
    /**
     * 任务附属变量
     */
    private string|null $variable;
    /**
     * 保持模型对象
     */
    private TaskModel $model;

    public function isMajor(): bool
    {
        return true;
    }

    public function getParentTaskId(): string
    {
        return $this->parent_task_id ?? '';
    }

    public function setParentTaskId(string $parentTaskId)
    {
        $this->parent_task_id = $parentTaskId;
    }

    public function getVariable(): string
    {
        return $this->variable ?? '';
    }

    public function setVariable(string $variable)
    {
        $this->variable = $variable;
    }

    public function getTaskName(): string
    {
        return $this->task_name ?? '';
    }

    public function setTaskName(string $taskName)
    {
        $this->task_name = $taskName;
    }

    public function getTaskType(): int
    {
        return $this->task_type ?? 0;
    }

    public function setTaskType(int $taskType): void
    {
        $this->task_type = $taskType;
    }

    public function getOperator(): string
    {
        return $this->operator ?? '';
    }

    public function setOperator(string $operator)
    {
        $this->operator = $operator;
    }

    public function getCreateTime(): string
    {
        return $this->create_time ?? '';
    }

    public function setCreateTime(string $createTime): void
    {
        $this->create_time = $createTime;
    }

    public function getFinishTime(): string
    {
        return $this->finish_time ?? '';
    }

    public function setFinishTime(string $finishTime)
    {
        $this->finish_time = $finishTime;
    }

    public function getExpireTime(): string
    {
        return $this->expire_time ?? '';
    }

    public function setExpireTime(string $expireTime)
    {
        $this->expire_time = $expireTime;
    }

    public function getActionUrl(): string
    {
        return $this->action_url ?? '';
    }

    public function setActionUrl(string $actionUrl): void
    {
        $this->action_url = $actionUrl;
    }

    public function getDisplayName(): string
    {
        return $this->display_name ?? '';
    }

    public function setDisplayName(string $displayName)
    {
        $this->display_name = $displayName;
    }

    public function getId(): string
    {
        return $this->id ?? '';
    }

    public function setId(string $id): void
    {
        $this->id = $id;
    }

    public function getOrderId(): string
    {
        return $this->order_id ?? '';
    }

    public function setOrderId(string $orderId)
    {
        $this->order_id = $orderId;
    }

    public function getActorIds(): array
    {
        if ($this->actorIds == null) {
            $map      = $this->getVariableMap();
            $actorStr = $map->{self::$KEY_ACTOR} ?? '';
            if (!empty($actorStr)) {
                $this->actorIds = explode(',', $actorStr);
            }
        }
        return $this->actorIds;
    }

    public function setActorIds(array $actorIds)
    {
        $this->actorIds = $actorIds;
    }

    public function getPerformType(): int
    {
        return $this->perform_type ?? 1;
    }

    public function setPerformType(int $performType)
    {
        $this->perform_type = $performType;
    }

    public function getVersion(): int
    {
        return $this->version ?? 1;
    }

    public function setVersion(int $version)
    {
        $this->version = $version;
    }

    public function getExpireDate(): string
    {
        return $this->expire_date ?? '';
    }

    public function setExpireDate(string $expireDate)
    {
        $this->expire_date = $expireDate;
    }

    public function getRemindDate(): string
    {
        return $this->remind_date ?? '';
    }

    public function setRemindDate(string $remindDate): void
    {
        $this->remind_date = $remindDate;
    }

    public function getModel(): TaskModel
    {
        return $this->model;
    }

    public function setModel(TaskModel $model): void
    {
        $this->model = $model;
    }

    public function getVariableMap(): object
    {
        return isset($this->variable) && empty($this->variable) ? json_decode($this->variable) : (object)[];
    }

    public function toString(): string
    {
        return json_encode(get_object_vars($this));

    }

    public function toArray(): array
    {
        return get_object_vars($this);
    }

}